| Conditions | 1 |
| Total Lines | 35 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | import React from 'react'; |
||
| 19 | |||
| 20 | render() { |
||
| 21 | 3 | const { importServersFromFile } = serversImporter; |
|
| 22 | 3 | const { onImport, createServers } = this.props; |
|
| 23 | 3 | const onChange = ({ target }) => |
|
| 24 | 1 | importServersFromFile(target.files[0]) |
|
| 25 | .then(createServers) |
||
| 26 | .then(onImport) |
||
| 27 | .then(() => { |
||
| 28 | // Reset input after processing file |
||
| 29 | 1 | target.value = null; |
|
| 30 | }); |
||
| 31 | |||
| 32 | 3 | return ( |
|
| 33 | <React.Fragment> |
||
| 34 | <button |
||
| 35 | type="button" |
||
| 36 | className="btn btn-outline-secondary mr-2" |
||
| 37 | id="importBtn" |
||
| 38 | 1 | onClick={() => this.fileRef.current.click()} |
|
| 39 | > |
||
| 40 | Import from file |
||
| 41 | </button> |
||
| 42 | <UncontrolledTooltip placement="top" target="importBtn"> |
||
| 43 | You can create servers by importing a CSV file with columns <b>name</b>, <b>apiKey</b> and <b>url</b> |
||
| 44 | </UncontrolledTooltip> |
||
| 45 | |||
| 46 | <input |
||
| 47 | type="file" |
||
| 48 | accept="text/csv" |
||
| 49 | className="create-server__csv-select" |
||
| 50 | ref={this.fileRef} |
||
| 51 | onChange={onChange} |
||
| 52 | /> |
||
| 53 | </React.Fragment> |
||
| 54 | ); |
||
| 59 |